﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="wucFileUpload.ascx.cs"
    Inherits="GMAC.ReportingSystem.UserControls.wucFileUpload" EnableTheming="true" %>
<div style="width: 300px; background-color: #F0F0FE">

    <script type="text/javascript">
        function fileUpload_OnChange(control, clientId)
        {
            var filePath = control.value;
            //if (filePath.indexOf('.') == -1)
            //    return false;

            var extension = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
            if (filePath.indexOf('.') == -1)
                extension = '';
            var filename = filePath.substring(filePath.lastIndexOf("\\") + 1);
            var lblFilename = document.getElementById(clientId + "_lblFilename");
            var hidFilename = document.getElementById(clientId + "_hidFilename");

            var hidExtensions = document.getElementById(clientId + "_hidExtensions");
            var extensions = hidExtensions.value.split("|");
            var isValid = false;
            if (extensions != null && extensions.length > 0)
            {
                for (var i = 0; i < extensions.length;  i++)
                {
                    if (extension == extensions[i])
                    {
                        isValid = true;
                        break;
                    }
                }
            }
           
            if (isValid)
            {
                lblFilename.innerHTML = filename.substring(0, 30) + "...";
                hidFilename.value = filename;
                return true;
            }
            else 
            {
                control.value = "";
                control.outerHTML = control.outerHTML;
                lblFilename.innerHTML = "";
                hidFilename.value = "";
                alert("Debe seleccionar un formato válido (" + extensions.join(", ") + ").");
                return false;
            }
        }

        function DeleteAttachment(controlId) {
            var fileUpload = document.getElementById(controlId + "_upload1");
            var lblFilename = document.getElementById(controlId + "_lblFilename");
            var hidFilename = document.getElementById(controlId + "_hidFilename");
            lblFilename.innerHTML = "";
            hidFilename.value = "";
            fileUpload.outerHTML = fileUpload.outerHTML;
            fileUpload.value = "";
        }

    </script>

    <table cellpadding="0" cellspacing="0">
        <tr>
            <td colspan="2">
                <table cellpadding="0" cellspacing="0">
                    <tr>
                        <td style="width: 30px;">
                            &nbsp;</td>
                        <td style="width: 220px" class="LabelLeft12px">
                            <asp:Label ID="lblFilename" runat="server" CssClass="FontVerdana"></asp:Label>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td class="LabelLeft12px" style="width: 60px;">
                &nbsp;</td>
            <td>
                <asp:FileUpload ID="upload1" runat="server" CssClass="TextBoxPadding" />
            </td>
        </tr>
    </table>
    <asp:HiddenField ID="hidFilename" runat="server" />
    <asp:HiddenField ID="hidExtensions" runat="server" />
</div>
